
import js2py

# js2py.eval_js('console.log("hello wrold")')
# func_js = """
# function add(a,b){
#     return a+b
# }
# """
# add = js2py.eval_js(func_js)
# print(add(1, 2))


# print(js2py.translate_js("console.log('hello world')"))

# 将js文件翻译为Python脚本
# js2py.translate_file('test.js', 'test.py')


# print("sum: ", sum([1, 2, 3]))

# context = js2py.EvalJs({'python_sum': sum})
# print("context.python_sum: ", context.python_sum)

# js_code = """
# python_sum([1,2,3])
# """
#
# print("js_code运行结果: ", context.eval(js_code))


# 使用pyimport语法
js_code = """
pyimport requests
console.log('导入成功');
var response = requests.get('http://www.baidu.com');
console.log(response.url);
console.log(response.content);
"""
js2py.eval_js(js_code)


# Python代码模拟JS代码
'''
juran:xxxxxxx
'''